package com.wd.home

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.wd.common.base.BaseViewModel
import com.wd.common.bean.LookcarBean
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * 作者：马海钊
 * 时间：2024/5/26 20:26
 * 功能：
 */
class HomeViewmodel :BaseViewModel() {
    //轮播图
    val homebanner: MutableLiveData<ArrayList<LookcarBean.XbannerBean>?> = MutableLiveData()
    fun hbanner() {
        api?.let {
            it.xbanner()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    homebanner.postValue(it.result)
                    Log.d("轮播图数据", it.result.toString() + it.message)
                }, { error ->
                    Log.e("error", error.message.toString())
                })
        }
    }

    //首页金刚区
    val homefindLiveData: MutableLiveData<LookcarBean.HomeFindBean> by lazy {
        MutableLiveData<LookcarBean.HomeFindBean>()
    }

    fun homefindind() {
        api?.let {
            it.homefind()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    homefindLiveData.postValue(it)
                    Log.d("金刚区数据", it.message.toString())
                }, { error ->
                    Log.e("error", error.message.toString())
                })
        }
    }

    //首页多条目
    val homeManyListLiveData: MutableLiveData<LookcarBean.HomeManyListBean> by lazy {
        MutableLiveData<LookcarBean.HomeManyListBean>()
    }
    fun homemanylist(page: Int, szie: Int) {
        api?.let {
            it.homemanylist(page, szie)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({
                    homeManyListLiveData.postValue(it)
                }, { error ->
                    Log.e("error", error.message.toString())
                })
        }
    }
}